package net.techwatch.guice.service;

import java.util.Date;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import net.techwatch.guice.aop.TimeSpentLog;
import net.techwatch.guice.dao.PersonDao;
import net.techwatch.guice.domain.Person;

@Singleton
public class PersonServiceImpl implements PersonService {

	@Override
	@TimeSpentLog
	public Person createPerson(String firstName, String lastName, Date birthDate) {
		return dao.create(lastName, firstName, birthDate);
	}

	private PersonDao dao;
	
	public PersonServiceImpl() {
		// nothing to do
	}

	public PersonDao getDao() {
		return dao;
	}

	@Inject
	public void setDao(PersonDao dao) {
		this.dao = dao;
	}

	public int numberOfPerson() {
		return dao.getAll().size();
	}

	public void updatePerson(Person person) {
		Person p = dao.findById(person.getId());
		p.setLastName(person.getLastName());
		p.setFirstName(person.getFirstName());
		p.setBirthDate(person.getBirthDate());
	}
}
